<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
	<title>木投网--个人中心--收货地址</title>
	<link rel="stylesheet" href="/resource/css/mt_index.css">
	<link rel="stylesheet" href="/resource/css/mt_user.css">
	<link rel="stylesheet" href="/resource/css/mt_showBo.css">
</head>
<body>
@include("common.shop_user_head")
		<div class="user-cont left">
			<div class="user-title">收货地址</div>
			<div class="address">
				<!-- 默认地址 -->
				@foreach($data as $data1)
					@if($data1->is_default == 1)
				<div class="add-box add-acquiesce left">
					@else

					<div class="add-box add-more left" >
						@endif
					<div class="add-bor"></div>
					<div class="til">
						<div class="left name">{{$data1->consignee}}</div>
						@if($data1->is_default == 1)
						<div class="right span"><a href="javascript:;">
								默认地址
							</a></div>
							@else
							<div class="right span"><a href="javascript:;" rel="{{$data1->address_id}}">

								</a></div>
						@endif
					</div>
					<div class="add-info">
						{{$data1->address_all}}{{$data1->address}}<br/>
						{{$data1->mobile}}
					</div>
					<div class="add-hover">
						@if($data1->is_default == 1)
							<a href="javascript:;" rel="{{$data1->address_id}}">修改</a>
								@else
							<a href="javascript:;" rel="{{$data1->address_id}}">修改</a>
							<a href="javascript:;" class="acquiesce"  rel="{{$data1->address_id}}">设为默认</a>

										@endif

					</div>
				</div>
				@endforeach
				<!-- 地址 -->

				<!-- 添加新地址 -->
				<div class="add-box add-new left">
					<a href="javascript:;" class="btn-new">
						<i></i>
						添加新地址
					</a>
				</div>
			</div>
		</div>

		@include("common.shop_user_foot")
				<!-- 添加新地址 -->
{{--<div class="popup"></div>
<div class="popup-add address-new">
	<div class="popup-bg">
		<div class="add-til">
			<span>新建收货地址</span>
			<div class="login-close"></div>
		</div>
		<form action="" class="form">
			<div class="form-group">
				<label for="">收货人：</label>
				<input type="text" class="form-control" id="consignee">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">联系方式：</label>
				<input type="text" class="form-control" id="mobile">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">收货地址</label>
				<select name="" id="sel_province" class="form-control form-right" ></select>
				<select name="" id="sel_city" class="form-control"></select>
				<select name="" id="sel_area" class="hide form-control"></select>
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">详细地址</label>
				<input type="text" class="form-control" id="address">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group form-left">
				<label for="check">
					<input type="checkbox" id="check" > 设为默认收货地址
				</label>
			</div>
			<div class="form-group">
				<button type="submit" class="btn-login" >保存</button>
			</div>
		</form>
	</div>
</div>
<div class="popup-add address-update">
	<div class="popup-bg">
		<div class="add-til">
			<span>修改地址</span>
			<div class="login-close"></div>
		</div>
		<form action="" class="form">
			<div class="form-group">
				<label for="">收货人：</label>
				<input type="text" class="form-control">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">联系方式：</label>
				<input type="text" class="form-control">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">收货地址</label>
				<select name="" id="sel_province1" class="form-control form-right"></select>
				<select name="" id="sel_city1" class="form-control"></select>
				<select name="" id="sel_area1" class="hide form-control"></select>
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group">
				<label for="">详细地址</label>
				<input type="text" class="form-control">
				<i class="i-red">*</i>
				<span></span>
			</div>
			<div class="form-group form-left">
				<label for="check">
					<input type="checkbox" id="check1" > 设为默认收货地址
				</label>
			</div>
			<div class="form-group">
				<button type="button" class="btn-login" rel="">保存</button>
			</div>
		</form>
	</div>
</div>--}}
<script src="/resource/js/jquery-1.11.3.min.js"></script>
<script src="/resource/js/province_city.js"></script>
<script src="/resource/js/mt_index.js"></script>
<script src="/resource/js/mt_showBo.js"></script>  <!-- 提示信息 -->



<script>
	region_init('sel_province','sel_city','sel_area');

	$('.add-more .til a').click(function(){
		var address_id = $(this).attr('rel');
		Showbo.Msg.confirm('<img class="left" src="/resource/img/user_if.png" alt=""><span style="float:left;font-size:22px;">您确定要删除该地址吗？</span>',function(btn){
			if (btn == 'yes') {
				$.ajax({

					url : '/delete_address',
					type : "POST",
					data : {address_id:address_id},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						if(json.code == 1){

							location=location
						}else{

						}
					}
				});

			}else{
				return false;
			};
		});
		$('input.btn+input.btn').css('margin-right','-12px');
	});
	$('a.acquiesce').click(function(){
		var address_id = $(this).attr('rel');

		$.ajax({

			url : '/default_address',
			type : "POST",
			data : {address_id:address_id},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				if(json.code == 1){

					location=location
				}else{

				}
			}
		});
	});
	//提交新地址
	$('.address-new .btn-login').click(function(){
		var is_default;
		if($('#check').is(':checked')){
			is_default =1;
		}else{
			is_default =0;
		}
		var consignee = $('#consignee').val();
		var mobile = $('#mobile').val();
		var sel_province = $('#sel_province').val();
		var sel_city = $('#sel_city').val();
		var address = $('#address').val();

		$.ajax({
			url : '/update_address',
			type : "POST",
			data : {is_default:is_default,consignee:consignee,mobile:mobile,address_all:sel_province+"-"+sel_city,address:address},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				if(json.code == 1){
					location=location
				}else{

				}
			}
		});
		//console.log(111);
	});
	//修改地址
	$('.address-update .btn-login').click(function(){
		var address_id = $(this).attr('rel');
		var is_default;
		var $consignee = $('.address-update .form-group').eq(0).children('.form-control');
		var $mobile = $('.address-update .form-group').eq(1).children('.form-control');
		var address_all;
		var $address_province = $('#sel_province1');
		var $address_city = $('#sel_city1');
		var $address = $('.address-update .form-group').eq(3).children('.form-control');
		if($('#check1').is(':checked')){
			is_default =1;
		}else{
			is_default =0;
		}
		$.ajax({
			url : '/update_address',
			type : "POST",
			data : {address_id:address_id,is_default:is_default,consignee:$consignee.val(),mobile:$mobile.val(),address_all:$address_province.val()+"-"+$address_city.val(),address:$address.val()},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				if(json.code == 1){
					location=location
				}else{

				}
			}
		});
		console.log($address_province.val());

	});

</script>
</body>
</html>